#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef struct TNode* PtrToTNode;
struct TNode {
    int data;
    PtrToTNode left;
    PtrToTNode right;
};
typedef PtrToTNode BinTree;

BinTree Insert ( BinTree BST, int X ) {
    if ( !BST ) {
        BST = (BinTree)malloc(sizeof(struct TNode));
        BST->data = X;
        BST->left = NULL;
        BST->right = NULL;
    } else {
        if ( X < BST->data ) BST->left = Insert(BST->left,X);
        else if ( X > BST->data ) BST->right = Insert(BST->right,X);
    }
    return BST;
}

void free_tree ( BinTree BST ) {
    if ( BST ) {
        free_tree(BST->left);
        free(BST);
        printf("Free Success\n");
        free_tree(BST->right);
    }
}

bool Check ( BinTree BST1, BinTree BST2 ) {
    if ( ( BST1 == NULL ) && ( BST2 == NULL ) ) return true;
    else if ( ( ( BST1 == NULL ) && ( BST2 != NULL ) ) || ( ( BST1 != NULL ) && ( BST2 == NULL ) ) ) return false;
    else if ( BST1->data != BST2->data ) return false;
    else if ( BST1->data == BST2->data ) return ( Check( BST1->left, BST2->left ) && Check( BST1->right, BST2->right ) );
}

int main () {
    BinTree BST1 = NULL, BST2 = NULL;
    int N, L, i, j, X;
    bool result;
    while (1) {
        BST1 = NULL;
        scanf("%d", &N);
        if ( N == 0 ) break;
        scanf("%d", &L);
        /* build BST1 */
        for ( i = 0; i < N; i++ ) {
            scanf("%d", &X);
            BST1 = Insert(BST1, X);
        }
        /* build BST2 */
        for ( j = 0; j < L; j++ ) {
            BST2 = NULL;
            for ( i = 0; i < N; i++ ) {
                scanf("%d", &X);
                BST2 = Insert(BST2, X);
            }
            result = Check(BST1,BST2);
            if ( result == true ) printf("Yes\n");
            else printf("No\n");
            free_tree(BST2);
        }
        free_tree(BST1);
    }
    return 0;
}